package com.kusiri.kframework.salesforce.valueobjectset
{
	import com.kusiri.kframework.salesforce.model.IKfSalesforceModel;
	import com.kusiri.kframework.salesforce.model.KfSalesforceModel;
	import com.kusiri.kframework.salesforce.model.valueobjectlist.SObjectList;
	
	import mx.collections.ArrayCollection;
	
	public class SoqlQueryValueObjectSet extends SObjectList implements ISoqlQueryValueObjectSet
	{
		// somewhere need this meta infornmation
		public static var iModel : Class = IKfSalesforceModel;
		
		private var _condition : String = '';
		
		public function get condition() : String
		{
			return _condition;
		}
		
		public function set condition(condition : String) : void
		{
			_condition = condition;
		}
				
		private var _sobjectType : String;
		
		public function get sobjectType() : String
		{
			return _sobjectType;
		}
		
		public function set sobjectType(type : String) : void
		{
			_sobjectType = type;
		}
		
		private var self:SoqlQueryValueObjectSet;

		
		public function SoqlQueryValueObjectSet()
		{
			self = this;
		}
		



		/**
		 * Get the value objects
		 */
		override public function refetchValueObjects(onSuccess : Function = null, onFail : Function = null) : void
		{
			var sfModel : KfSalesforceModel = model as KfSalesforceModel;
			sfModel.getSObjects(sobjectType, condition, 
				function (result:ArrayCollection) : void
				{
					_valueObjects = result.source;
					if (onSuccess != null) onSuccess(self);
				},
				function (e:*) : void
				{
					if (onFail != null) onFail(e);
				}
			);	
		}
	}
}